package com.powerunion.datacollection.workflow.fsm.core.task;

import com.powerunion.datacollection.workflow.fsm.WFTask;
import com.powerunion.datacollection.workflow.fsm.schedule.WFTaskSchedule;
import com.powerunion.datacollection.workflow.fsm.state.task.WFTaskRunningState;
import com.powerunion.datacollection.workflow.fsm.state.task.WFTaskStartState;
import com.powerunion.datacollection.workflow.fsm.state.task.WFTaskSuspendState;

public class TaskFactory {

	private static TaskFactory instance;
	 /**
     * 初始化状态
     */
    public static final int INITIALIZED = 0;
    /**
     * 运行状态
     */
    public static final int RUNNING = 1;
    /**
     * 挂起状态
     */
    public static final int SUSPEND = 2;
    /**
     * 已经结束
     */
    public static final int COMPLETED = 3;
    /**
     * 被撤销
     */
    public static final int CANCELED = 9;
    
    private static  WFTaskContext context;
    
    private TaskFactory(){
    	context = new WFTaskContext();
    }
	
	public static TaskFactory instance() {
		if (instance == null) {
			instance = new TaskFactory();
		}
		return instance;
	}
	
	public static WFTask getTask(int status){
		WFTask task = null;
		switch(status){
		case INITIALIZED:
			context.setCurrentState(new WFTaskStartState());
			break;
		case RUNNING:
			context.setCurrentState(new WFTaskRunningState());
			break;
		case SUSPEND:
			context.setCurrentState(new WFTaskSuspendState());
			break;
		case COMPLETED:
			context.setCurrentState(new WFTaskRunningState());
			break;
		case CANCELED:
			context.setCurrentState(new WFTaskRunningState());
			break;
		}
		task = context.getCurrentState();
		return task;
	}

}
